import {
    cardWidth,
    sidebarEl,
    ulListEl,
    iconEl
} from './varible.js';

function delPx(number) {
    return number.split("px")[0];
}

function numberToCard(number, top) {
    return ((number - 1) * -1 * cardWidth + "px " + top + "px");
}
//菜单栏的点击事件
function playClick() {
    sidebarEl.addEventListener('click', function () {
        if (ulListEl.style.display == 'block') {
            ulListEl.style.display = 'none';
            iconEl.src = "../static/img/tab_bottom.png";
        } else {
            ulListEl.style.display = 'block';
            iconEl.src = "../static/img/tab_top.png";
        }
    })
}
//渲染过程中改变位置
function changeLocation(array, index, width) {

    let fIndex = index;
    while (array[fIndex][2] != -1) {
        let cIndex = fIndex;
        fIndex = array[fIndex][2];
        //父节点只在第一节子节点移动时跟着移动相同位置
        if (array[fIndex][8] != cIndex) {
            array[fIndex][0] += width;
            if (array[fIndex][10] != -1) {
                array[array[fIndex][9]][0] = array[fIndex][0] - (width / 4 * 3);
                array[array[fIndex][10]][0] = array[fIndex][0] + (width / 4 * 3);
            } else if (array[fIndex][9] != -1) {
                array[array[fIndex][9]][0] = array[fIndex][0];
            }
        } else {
            break;
        }
        if (array[fIndex][3] != -1) {
            array[array[fIndex][3]][0] += width;
            changeLocation(array, array[fIndex][3], width);
        }
    }
    if (array[index][3] != -1) {
        array[array[index][3]][0] += width;
        changeLocation(array, array[index][3], width);
    }

}
export {
    delPx,
    numberToCard,
    playClick,
    changeLocation
}